﻿using System;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SharePointUtilitiesForDevelopers.Tests
{
    
    /// <summary>
    ///Test class for <see cref="SharePointQueryOptionsExtensionMethods"/>.
    ///</summary>
    [TestClass]
    public class SharePointQueryOptionsExtensionMethodsTest
    {
        [TestMethod]
        public void ToSharePointQueryOptions_returns_object_when_input_is_null()
        {
            XElement xml = null;
            var options = xml.ToSharePointQueryOptions();
            Assert.IsNotNull(options);
        }

        [TestMethod] 
        public void QueryOptions_ToSharePointQueryOptionsTest_should_return_correct_xml()
        {
            var options = new SharePointQueryOptions();
            options.DateInUtc = false;
            options.ViewAttributesScopeRecursive = true;
            options.PagingListItemCollectionPositionNext = "pagingTest";
            options.IncludeMandatoryColumns = false;
            options.Folder = "folderTest";
            var xml = options.ToQueryOptionsXElement();
            var optionsFromXml = xml.ToSharePointQueryOptions();
            Assert.AreEqual(options.DateInUtc, optionsFromXml.DateInUtc);
            Assert.AreEqual(options.Folder, optionsFromXml.Folder);
            Assert.AreEqual(options.IncludeMandatoryColumns, optionsFromXml.IncludeMandatoryColumns);
            Assert.AreEqual(options.MeetingInstanceID, optionsFromXml.MeetingInstanceID);
            Assert.AreEqual(options.PagingListItemCollectionPositionNext, optionsFromXml.PagingListItemCollectionPositionNext);
            Assert.AreEqual(options.ViewAttributesScopeRecursive, optionsFromXml.ViewAttributesScopeRecursive);
        }

        [TestMethod]
        public void String_ToSharePointQueryOptionsTest_should_return_correct_xml()
        {
            var xml =
                "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc></QueryOptions>";

            var queryOptions = xml.ToQueryOptionsXElement();

        }
        
        [TestMethod]
        public void QueryOptions_ToSharePointQueryOptionsTest_should_return_empty_queryoptions_element_when_input_is_null()
        {
            SharePointQueryOptions options = null;
            var xml = options.ToQueryOptionsXElement();
            Assert.AreEqual("<QueryOptions />", xml.ToString());
        }

    }
}
